home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Demos / Pascal Demos / MultiSkel / MSkelEdit.p next >
Encoding:
Text File  |  1994-02-23  |  2.5 KB  |  150 lines  |  [TEXT/PJMM]

  1. unit MultiSkelEdit;
  2.  
  3. interface
  4.  
  5.     uses
  6.         TransSkel, MultiSkelGlobals;
  7.  
  8.     procedure EditWindInit;
  9.     procedure EditWindEditMenu (item: Integer);
  10.  
  11. implementation
  12.  
  13.     const
  14.         undo = 1;
  15.         cut = 3;
  16.         copy = 4;
  17.         paste = 5;
  18.         clear = 6;
  19.  
  20.     var
  21.  
  22.         teEdit: TEHandle;
  23.  
  24.  
  25.     procedure Mouse (pt: Point;
  26.                                     t: LongInt;
  27.                                     mods: Integer);
  28.     begin
  29.         TEClick(pt, Boolean(BitAnd(mods, shiftKey) <> 0), teEdit);
  30.     end;
  31.  
  32.  
  33.     procedure Key (c: char;
  34.                                     code: Integer;
  35.                                     mods: Integer);
  36.     begin
  37.         TEKey(c, teEdit);
  38.     end;
  39.  
  40.  
  41.     procedure Update (resized: Boolean);
  42.         var
  43.             r: Rect;
  44.     begin
  45.         r := editWind^.portRect;
  46.         EraseRect(r);
  47.         r.left := r.left + 4;
  48.         r.bottom := r.bottom - 2;
  49.         r.top := r.top + 2;
  50.         r.right := r.right - 19;
  51.         if (resized) then
  52.             begin
  53.                 teEdit^^.destRect.right := r.right;
  54.                 teEdit^^.viewRect := r;
  55.                 TECalText(teEdit);
  56.             end;
  57.         DrawGrowBox(editWind);
  58.         TEUpdate(r, teEdit);
  59.     end;
  60.  
  61.  
  62.     procedure Activate (active: Boolean);
  63.     begin
  64.         DrawGrowBox(editWind);
  65.         if (active) then
  66.             begin
  67.                 TEActivate(teEdit);
  68.                 DisableItem(editMenu, undo);
  69.             end
  70.         else
  71.             begin
  72.                 TEDeactivate(teEdit);
  73.                 EnableItem(editMenu, undo);
  74.             end;
  75.     end;
  76.  
  77.  
  78.     procedure Clobber;
  79.     begin
  80.         TEDispose(teEdit);
  81.         DisposeWindow(editWind);
  82.     end;
  83.  
  84.  
  85.     procedure Idle;
  86.     begin
  87.         TEIdle(teEdit);
  88.     end;
  89.  
  90.  
  91.     procedure EditWindInit;
  92.         var
  93.             r: Rect;
  94.             str: Str255;
  95.             ignore: Boolean;
  96.     begin
  97.         if (SkelQuery(skelQHasColorQD) <> 0) then
  98.             editWind := GetNewCWindow(editWindRes, nil, WindowPtr(-1))
  99.         else
  100.             editWind := GetNewWindow(editWindRes, nil, WindowPtr(-1));
  101.         if (editWind = nil) then
  102.             exit(EditWindInit);
  103.         ignore := SkelWindow(editWind, @Mouse, @Key, @Update, @Activate, nil, @Clobber, @Idle, true);
  104.  
  105.         TextFont(0);
  106.         TextSize(0);
  107.  
  108.         r := editWind^.portRect;
  109.         r.left := r.left + 4;
  110.         r.bottom := r.bottom - 2;
  111.         r.top := r.top + 2;
  112.         r.right := r.right - 19;
  113.         teEdit := TENew(r, r);
  114.         str := 'This is the text editing window.X';
  115.         str[length(str)] := chr(13);    { make last char (X) a carriage return }
  116.         TEInsert(Ptr(LongInt(@str) + 1), LongInt(length(str)), teEdit);
  117.     end;
  118.  
  119.  
  120.     procedure EditWindEditMenu (item: Integer);
  121.         var
  122.             ignore: OSErr;
  123.     begin
  124.         case item of
  125.             cut: 
  126.                 begin
  127.                     TECut(teEdit);
  128.                     ignore := ZeroScrap;
  129.                     ignore := TEToScrap;
  130.                 end;
  131.             copy: 
  132.                 begin
  133.                     TECopy(teEdit);
  134.                     ignore := ZeroScrap;
  135.                     ignore := TEToScrap;
  136.                 end;
  137.             paste: 
  138.                 begin
  139.                     ignore := TEFromScrap;
  140.                     TEPaste(teEdit);
  141.                 end;
  142.             clear: 
  143.                 begin
  144.                     TEDelete(teEdit);
  145.                 end;
  146.         end;
  147.     end;
  148.  
  149.  
  150. end.